package com.cn.nio.multinio;

import com.cn.nio.multinio.AcceptorThread;
import com.cn.nio.multinio.DoWorkThread;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;


@Slf4j
public class NioMultiThread3 {


  public static void main(String[] args) {

    try {
      ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
      serverSocketChannel.bind(new InetSocketAddress(9999));
      serverSocketChannel.configureBlocking(false);

      AcceptorThread acceptorThread = new AcceptorThread(serverSocketChannel, 2);
      acceptorThread.start();

      DoWorkThread readerThread = new DoWorkThread();
      readerThread.start();

      DoWorkThread readerThread2 = new DoWorkThread();
      readerThread2.start();

    } catch (IOException e) {
      e.printStackTrace();
    }

  }

  //监听 之后 获取的channel 通过队列分发出去
  public volatile static LinkedBlockingQueue<SocketChannel>[] queue = null;

  public static AtomicInteger idMachine = new AtomicInteger();

}
